
<template>
  <base-page-view class-name="page-container" :show-to-top="false">
    <view class="mine-wechat-card">
      <view class="wechat-card">
        <b-image src="/static/images/mine/bg_wechat_card.png" :is-asset="true" class-name="bg-card" />
        <view class="center-box">
          <view class="c-h1">我的二维码</view>
          <view class="top" @click="uploadImage">
            <image v-if="weixincode" class="qr-code" :src="weixincode" />
            <view v-else class="rCont needsclick">
              <image class="icon needsclick" src="/static/images/icon/icon_wechat_card_add.png" />
            </view>
          </view>
          <view class="bottom" @click="toPage">
            1、微信二维码名片怎么生成?
          </view>
        </view>
      </view>
      <view class="btn" @click="uploadQrCode">上传微信二维码</view>
    </view>
  </base-page-view>
</template>

<script>
import { mapGetters } from 'vuex'
import './index.scss'
export default {
  components: {
  },
  data() {
    return {
      weixincode: ''
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ])
  },
  onLoad() {
    console.log(this.user)
    this.weixincode = this.user.weixincode
  },
  methods: {
    async uploadImage() {
      const data = await this.$api.commonApi.uploadImg({ count: 1 })
      if (data.success) {
        this.weixincode = data.url[0].url
      }
    },
    toPage() {
      this.$navigateTo('/pagesMine/rule/index?type=wechatHelp')
    },
    async uploadQrCode() {
      if (!this.weixincode) {
        this.showToast('请选择图片')
        return
      }
      const res = await this.$api.mineApi.setMyInfo({
        weixincode: this.weixincode
      })
      if (res.success) {
        this.showToast('上传成功')
      }
    },
    showToast(msg) {
      uni.showToast({
        title: msg,
        icon: 'none',
        duration: 2000,
        mask: true
      })
    }
  }
}
</script>
